package com.ruoyi.device.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.device.domain.GraphicsLibrary;
import com.ruoyi.device.mapper.GraphicsLibraryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.device.mapper.GraphicsLibraryTypeMapper;
import com.ruoyi.device.domain.GraphicsLibraryType;
import com.ruoyi.device.service.IGraphicsLibraryTypeService;

import static com.ruoyi.common.security.utils.SecurityUtils.getLoginUser;

/**
 * 图元图形库类型Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-09-19
 */
@Service
public class GraphicsLibraryTypeServiceImpl implements IGraphicsLibraryTypeService 
{
    @Autowired
    private GraphicsLibraryTypeMapper graphicsLibraryTypeMapper;
    @Autowired
    private GraphicsLibraryMapper graphicsLibraryMapper;

    /**
     * 查询图元图形库类型
     * 
     * @param id 图元图形库类型主键
     * @return 图元图形库类型
     */
    @Override
    public GraphicsLibraryType selectGraphicsLibraryTypeById(Long id)
    {
        return graphicsLibraryTypeMapper.selectGraphicsLibraryTypeById(id);
    }

    /**
     * 查询图元图形库类型列表
     * 
     * @param graphicsLibraryType 图元图形库类型
     * @return 图元图形库类型
     */
    @Override
    public List<GraphicsLibraryType> selectGraphicsLibraryTypeList(GraphicsLibraryType graphicsLibraryType)
    {
        return graphicsLibraryTypeMapper.selectGraphicsLibraryTypeList(graphicsLibraryType);
    }

    /**
     * 新增图元图形库类型
     * 
     * @param graphicsLibraryType 图元图形库类型
     * @return 结果
     */
    @Override
    public int insertGraphicsLibraryType(GraphicsLibraryType graphicsLibraryType)
    {
        graphicsLibraryType.setCreateBy(getLoginUser().getUsername());
        graphicsLibraryType.setCreateTime(DateUtils.getNowDate());
        return graphicsLibraryTypeMapper.insertGraphicsLibraryType(graphicsLibraryType);
    }

    /**
     * 修改图元图形库类型
     * 
     * @param graphicsLibraryType 图元图形库类型
     * @return 结果
     */
    @Override
    public int updateGraphicsLibraryType(GraphicsLibraryType graphicsLibraryType)
    {
        graphicsLibraryType.setUpdateBy(getLoginUser().getUsername());
        graphicsLibraryType.setUpdateTime(DateUtils.getNowDate());
        return graphicsLibraryTypeMapper.updateGraphicsLibraryType(graphicsLibraryType);
    }

    /**
     * 批量删除图元图形库类型
     * 
     * @param ids 需要删除的图元图形库类型主键
     * @return 结果
     */
    @Override
    public int deleteGraphicsLibraryTypeByIds(Long[] ids)
    {
        return graphicsLibraryTypeMapper.deleteGraphicsLibraryTypeByIds(ids);
    }

    /**
     * 删除图元图形库类型信息
     * 
     * @param id 图元图形库类型主键
     * @return 结果
     */
    @Override
    public int deleteGraphicsLibraryTypeById(Long id)
    {
        return graphicsLibraryTypeMapper.deleteGraphicsLibraryTypeById(id);
    }

    @Override
    public Map<String, Object> selectGraphicsLibraryTypeGetMaotu() {
        Map<String, Object> result = new HashMap<>();
        //1.获取图元图形库类型列表
        List<GraphicsLibraryType> graphicsLibraryTypes = graphicsLibraryTypeMapper.selectGraphicsLibraryTypeList(null);
        for (GraphicsLibraryType graphicsLibraryType : graphicsLibraryTypes) {
            //key值为图元图形库类型名称，value值为图元图形库列表
            result.put("key", graphicsLibraryType.getName());
            GraphicsLibrary graphicsLibrary = new GraphicsLibrary();
            graphicsLibrary.setGId(graphicsLibraryType.getId());
            List<GraphicsLibrary> graphicsLibraries = graphicsLibraryMapper.selectGraphicsLibraryList(graphicsLibrary);
            result.put("value", graphicsLibraries);
        }
        return result;
    }
}
